<template>
  <div>
    <el-form inline :model="queryData" ref="queryData" class="query-form">
      <el-form-item label="用户手机:" prop="phone">
        <el-input type="number" v-model="queryData.phone" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('phone')"/>
      </el-form-item>
      <el-form-item label="成为时间:" prop="createTime">
        <el-date-picker v-model="queryData.createTime" value-format="yyyy-MM-dd" type="date" style="width: 200px" @clear="formClear('name')" placeholder="选择日期"></el-date-picker>
      </el-form-item>
      <el-form-item label="房源经纪人:" prop="name">
        <el-input v-model="queryData.name" placeholder="请输入" style="width: 200px" clearable
                  @clear="formClear('name')"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查 询</el-button>
        <el-button @click="onReset">重 置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableList" border style="width: 100%;">
      <el-table-column prop="id" label="UUID" align="center"/>
      <el-table-column label="用户头像" align="center">
        <template slot-scope="{row}">
          <el-image style="width: 30px; height: 30px; border-radius: 50%" :src="row.avatar" fit="cover"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="用户昵称" align="center" show-overflow-tooltip/>
      <el-table-column prop="phone" label="用户手机" align="center" show-overflow-tooltip/>
      <el-table-column prop="sex" label="用户性别" align="center"/>
      <el-table-column prop="nickName" label="微信昵称" align="center"/>
      <el-table-column prop="userId" label="WXID" align="center"/>
      <el-table-column prop="createTime" label="成为经纪人时间" align="center" width="150"/>
      <el-table-column label="房源经纪人" align="center" width="100">
        <template slot-scope="{row}">
          <el-switch :value="row.sign" active-color="#13ce66"
                     :active-value="1" :inactive-value="0" @change="switchChange($event, row)"></el-switch>
        </template>
      </el-table-column>
    </el-table>
    <Paging v-model="queryData" @change="getRequest"></Paging>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'

  export default {
    computed: {
      ...mapGetters(['confirm'])
    },
    name: 'entrustAgentList',
    data() {
      return {
        tableList: [],
        queryData: {
          createTime: null, // 创建时间
          id: null, //
          name: null, // 姓名
          phone: null, // 手机号
          pageNum: 1,
          pageSize: 10,
          total: 0
        }
      }
    },
    beforeMount() {
      this.getRequest()
    },
    methods: {
      /**
       * 上下架事件
       */
      switchChange(event, row) {
        this.$confirm('确认要修改当前状态吗?', '提示', this.confirm.options).then(async() => {
          await this.$ajax.post(`/my/house/agent/update`, { id: row.id, sign: event })
          this.$message.success('操作成功!')
          this.getRequest()
        })
      },
      /**
       * 重置事件
       */
      onReset() {
        this.queryData.pageNum = 1
        this.$refs['queryData'].resetFields()
        this.getRequest()
      },
      /**
       * 查询条件提交事件
       */
      onSubmit() {
        this.queryData.pageNum = 1
        this.getRequest()
      },

      /**
       * 列表请求事件
       */
      async getRequest() {
        const params = JSON.parse(JSON.stringify(this.queryData))
        const res = await this.$ajax.get('/my/house/agent/backstage/agent/list', { params })
        this.queryData.total = res.total
        this.tableList = res.rows
      },
      /**
       * form置空事件
       */
      formClear(key) {
        this.queryData[key] = null
        this.onSubmit()
      }
    }
  }
</script>

<style scoped>
::v-deep input::-webkit-outer-spin-button,
::v-deep input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
/deep/ input[type='number'] {
  -moz-appearance: textfield !important;
  }
</style>
